package com.cskaoyan.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 注册一个DruidDataSource 1.0
 * @author stone
 * @date 2022/01/04 16:00
 */
//@Configuration
public class DruidDataSourceConfiguration {

    /*@Bean
    public DruidDataSource dataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://localhost:3306/cskaoyan_db");
        dataSource.setUsername("root");
        dataSource.setPassword("123456");
        return dataSource;
    }*/
    @Value("${druid.datasource.driver}")
    String className;
    @Value("${druid.datasource.url}")
    String url;
    @Value("${druid.datasource.username}")
    String username;
    @Value("${druid.datasource.password}")
    String password;
    @Bean
    public DruidDataSource dataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(className);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }
}
